package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常拦截
 */
@RestControllerAdvice
@Slf4j
public class BasicExceptionHandler {

    @ExceptionHandler(NcException.class)
    public Result resolveNcException(NcException exception){
        exception.printStackTrace();
        return Result.errorCodeMessage(exception.getCode(), exception.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public Result resolveException(Exception exception){
        exception.printStackTrace();
        return Result.errorCodeMessage(ResponseEnum.SERVER_ERROR.getCode(), ResponseEnum.SERVER_ERROR.getMessage());
    }

}